package com.epmis.epmis.Service.impl;

import com.epmis.epmis.Mapper.LoginMapper;
import com.epmis.epmis.Mapper.MissionMapper;
import com.epmis.epmis.Mapper.ProjectMapper;
import com.epmis.epmis.Mapper.UserMapper;
import com.epmis.epmis.Service.UserService;
import com.epmis.epmis.pojo.*;
import com.epmis.epmis.utils.ImageUitl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Sets;
import io.goeasy.GoEasy;

import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.io.IOException;
import java.sql.Array;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;
    @Resource
    LoginMapper loginMapper;
    @Resource
    ProjectMapper projectMapper;
    @Resource
    MissionMapper missionMapper;

    public Enterprise getEnterpriseName(String id) {
        return  userMapper.getEnterpriseName(Integer.valueOf(id));
    }

    @Override
    public Department getDepartmentName(int id) {
        return userMapper.getDepartmentName(id);
    }

    @Override
    public int updateUserName(String username, int userId) {
        User user = userMapper.isExistSameUsername(username);
        if(user != null){
            return  0;
        }
        HashMap map = new HashMap<>();
        map.put("username",username);
        map.put("userId",userId);
        return userMapper.updateUserName(map);
    }

    @Override
    public Post getPostName(int id) {
        return userMapper.getPostName(id);
    }

    @Override
    public List getMemberMessage(int enterprise_id) {
        return userMapper.getMemberMessage(enterprise_id);
    }

    @Override
    public List<Notification> getUserReadNotification(int recipient_id) {
        List<Notification> list = userMapper.getUserReadNotification(recipient_id);
        long newDate = new Date().getTime();
        list.stream().map( res -> {
            try {
                res.setIssuer_photo("data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(res.getIssuer_photo()));
                res.getDate().getTime();
                long spent =  newDate - res.getDate().getTime();
                if(spent / 1000 == 0){
                    res.setTime("刚刚");
                }else if(spent / 1000 < 60){
                    res.setTime( spent / 1000 + "秒前");
                }else if(spent / (1000 * 60) < 60){
                    res.setTime( spent /  (1000 * 60) + "分钟前");
                }else if(spent / (1000 * 60 * 60) < 24){
                    res.setTime( spent /  (1000 * 60 * 60) + "小时前");
                }else {
                    res.setTime( spent /  (1000 * 60 * 60 * 24) + "天前");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<Notification> getUserUnReadNotification(int recipient_id) {
        List<Notification> list = userMapper.getUserUnReadNotification(recipient_id);
        long newDate = new Date().getTime();
        list.stream().map( res -> {
            try {
                res.setIssuer_photo("data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(res.getIssuer_photo()));
                res.getDate().getTime();
                long spent =  newDate - res.getDate().getTime();
                if(spent / 1000 == 0) {
                    res.setTime("刚刚");
                }else if(spent / 1000 < 60){
                    res.setTime( spent / 1000 + "秒前");
                }else if(spent / (1000 * 60) < 60){
                    res.setTime( spent /  (1000 * 60) + "分钟前");
                }else if(spent / (1000 * 60 * 60) < 24){
                    res.setTime( spent /  (1000 * 60 * 60) + "小时前");
                }else {
                    res.setTime( spent /  (1000 * 60 * 60 * 24) + "天前");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getMissionComment(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Comment> comments = missionMapper.getMissionComment(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(comments);
        List<Comment> comment = pageInfo.getList();
        List<HashMap<String,Object>> list = comment.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            User user = userMapper.getUserMessage(res.getIssuer_id());
            newMap.put("issuerId",res.getIssuer_id());
            newMap.put("name",user.getName());
            try {
                newMap.put("headImageUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("date",sdf.format(res.getComment_date()));
            newMap.put("content",res.getContent());
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }


    @Override
    public PageInfo<HashMap<String, Object>> getExamineComment(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Comment> comments = missionMapper.getExamineComment(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(comments);
        List<Comment> comment = pageInfo.getList();
        List<HashMap<String,Object>> list = comment.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            User user = userMapper.getUserMessage(res.getIssuer_id());
            newMap.put("issuerId",res.getIssuer_id());
            newMap.put("name",user.getName());
            try {
                newMap.put("headImageUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("date",sdf.format(res.getComment_date()));
            newMap.put("content",res.getContent());
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getMissionActivity(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Activity> activities = missionMapper.getMissionActivity(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(activities);
        List<Activity> activity = pageInfo.getList();
        List<HashMap<String,Object>> list = activity.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            User user = userMapper.getUserMessage(res.getUpdate_p_id());
            newMap.put("updatePerson",user.getName());
            try {
                newMap.put("headImageUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("updateTime",sdf.format(res.getUpdate_date()));
            newMap.put("updateContent",res.getUpdate_content());
            if(res.getUpdate_before() == null){
                newMap.put("updateBefore","");
            }else{
                newMap.put("updateBefore",res.getUpdate_before());
            }

            if(res.getUpdate_after() == null){
                newMap.put("updateAfter","");
            }else{
                newMap.put("updateAfter",res.getUpdate_after());
            }
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getSonMission(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<MissionProject> missionProjects = missionMapper.getSonMission(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(missionProjects);
        List<MissionProject> missionProject = pageInfo.getList();
        List<HashMap<String,Object>> list = missionProject.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getMission_id());
            newMap.put("status",res.getPM_state());
            Mission mission = missionMapper.getMission(res.getMission_id());
            newMap.put("name",mission.getTitle());
            User user = userMapper.getUserMessage(mission.getPrincipal_id());
            newMap.put("principal",user.getName());
            try {
                newMap.put("circleUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("over",sdf.format(mission.getOver_date()));
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getRelMission(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<MissionProject> missionProjects = missionMapper.getRelMission(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(missionProjects);
        List<MissionProject> missionProject = pageInfo.getList();
        List<HashMap<String,Object>> list = missionProject.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getMission_id());
            newMap.put("status",res.getPM_state());
            Mission mission = missionMapper.getMission(res.getMission_id());
            newMap.put("name",mission.getTitle());
            User user = userMapper.getUserMessage(mission.getPrincipal_id());
            newMap.put("principal",user.getName());
            try {
                newMap.put("circleUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("over",sdf.format(mission.getOver_date()));
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getBeforeMission(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Mission> missions = missionMapper.getBeforeMission(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(missions);
        List<Mission> mission = pageInfo.getList();
        List<HashMap<String,Object>> list = mission.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            newMap.put("name",res.getTitle());
            String type = res.getType();
            switch (type){
                case "项目目标":
                    newMap.put("status",missionMapper.getTargetMessage(res.getId()).getTarget_status());
                    break;
                case "项目费用":
                    newMap.put("status",missionMapper.getCostMessage(res.getId()).getCost_state());
                    break;
                case "项目任务":
                    newMap.put("status",missionMapper.getMissionProjectMessage(res.getId()).getPM_state());
                    break;
            }

            if(res.getPrincipal_id() == 0){
                newMap.put("principal","无");
                newMap.put("circleUrl","");
            }else{
                User user = userMapper.getUserMessage(res.getPrincipal_id());
                newMap.put("principal",user.getName());
                try {
                    newMap.put("circleUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(res.getOver_date() == null){
                newMap.put("over","");
            }else{
                newMap.put("over",sdf.format(res.getOver_date()));
            }
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getAfterMission(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Mission> missions = missionMapper.getAfterMission(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(missions);
        List<Mission> mission = pageInfo.getList();
        List<HashMap<String,Object>> list = mission.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            newMap.put("name",res.getTitle());
            String type = res.getType();
            switch (type){
                case "项目目标":
                    newMap.put("status",missionMapper.getTargetMessage(res.getId()).getTarget_status());
                    break;
                case "项目费用":
                    newMap.put("status",missionMapper.getCostMessage(res.getId()).getCost_state());
                    break;
                case "项目任务":
                    newMap.put("status",missionMapper.getMissionProjectMessage(res.getId()).getPM_state());
                    break;
            }

            if(res.getPrincipal_id() == 0){
                newMap.put("principal","无");
                newMap.put("circleUrl","");
            }else{
                User user = userMapper.getUserMessage(res.getPrincipal_id());
                newMap.put("principal",user.getName());
                try {
                    newMap.put("circleUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(res.getOver_date() == null){
                newMap.put("over","");
            }else{
                newMap.put("over",sdf.format(res.getOver_date()));
            }
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getMissionWork(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Hour> hours = missionMapper.getMissionWork(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        PageInfo pageInfo = new PageInfo<>(hours);
        List<Hour> hour = pageInfo.getList();
        List<HashMap<String,Object>> list = hour.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            newMap.put("time",res.getHour());
            newMap.put("type",res.getWork_type());
            if(res.getDescription() == null){
                newMap.put("description","");
            }else{
                newMap.put("description",res.getDescription());
            }

            User user = userMapper.getUserMessage(res.getRegistrant_id());
            newMap.put("registerId",user.getId());
            newMap.put("register",user.getName());
            try {
                newMap.put("circleUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("date",sdf.format(res.getWork_date()));
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HashMap<String, Object>> getMissionFile(int pageCode, int pageSize, String id) {
        PageHelper.startPage(pageCode,pageSize);
        List<Accessory> accessories = missionMapper.getMissionFile(Integer.valueOf(id));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageInfo pageInfo = new PageInfo<>(accessories);
        List<Accessory> accessory = pageInfo.getList();
        List<HashMap<String,Object>> list = accessory.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            newMap.put("name",res.getAccessory_name());
            User user = userMapper.getUserMessage(res.getUploading_p_id());
            newMap.put("person",user.getName());
            newMap.put("large",res.getAccessory_size());
            newMap.put("creatorId",res.getUploading_p_id());
            newMap.put("url",res.getUrl());
            try {
                newMap.put("circleUrl","data:image/jpeg;base64,"+ ImageUitl.ImageToBase64ByLocal(user.getPhoto()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            newMap.put("date",sdf.format(res.getUploading_date()));
            return newMap;
        }).collect(Collectors.toList());
        pageInfo.setList(list);
        return pageInfo;
    }

    @Override
    public int updateHeadImg(String ImgName,int userId) {
        HashMap map = new HashMap<>();
        map.put("ImgName",ImgName);
        map.put("userId",userId);
        userMapper.updateNotificationPhoto(map);
        return userMapper.updateHeadImg(map);
    }

    @Override
    public int updatePassword(String newPassword,String oldPassword,String username) {
        User user = loginMapper.getUserMessage(username);
        if(!user.getPassword().equals(oldPassword)){
            return 0;
        }
        HashMap map = new HashMap<>();
        map.put("password",newPassword);
        map.put("userId",user.getId());
        return userMapper.updatePassword(map);
    }

    @Override
    public int updatePhone(String phone, int userId) {
        User user = loginMapper.havePhone(phone);
        if(user != null){
            return 0;
        }
        HashMap map = new HashMap<>();
        map.put("phone",phone);
        map.put("userId",userId);
        return userMapper.updatePhone(map);

    }

    @Override
    public int updateEmail(String email, int userId) {
        User user = loginMapper.haveEmail(email);
        if(user != null) {
            return 0;
        }
        HashMap map = new HashMap<>();
        map.put("email",email);
        map.put("userId",userId);
        return userMapper.updateEmail(map);
    }

    @Override
    public int createProject(HashMap<String,Object> map){
        Project project = new Project();
        GoEasy goEasy = new GoEasy("rest-hangzhou.goeasy.io","BC-f92a140e428c4ce79442bafc26e543d8");
        project.setProject_number((String) map.get("number"));
        int enterpriseId = (Integer.valueOf((String) map.get("enterprise_id")));
        if(userMapper.isExistSameNumber((String) map.get("number"),String.valueOf(enterpriseId)) !=null){
            return 0;
        }
        int userId = Integer.valueOf((String) map.get("creatorId"));
        String issuerName = userMapper.getUserMessage(userId).getName();
        String issuerPhoto = userMapper.getUserMessage(userId).getPhoto();
        String projectName = (String) map.get("name");
        String projectsMembers = "";

        ArrayList list = (ArrayList) map.get("projectsMembers");
        for(int i = 0;i < list.size();i++){
            if(i == 0){
                projectsMembers = "," + projectsMembers + list.get(i) + ",";
            }else{
                projectsMembers = projectsMembers + list.get(i) + ",";
            }
        }

        Notification notification = new Notification();
        project.setProject_name(projectName);
        project.setRouge(Integer.valueOf((String) map.get("scopeValue")));
        project.setDescription((String) map.get("projectsContent"));
        project.setMember_id(projectsMembers);
        project.setCreator_id(userId);
        project.setCreate_date(new Timestamp((new java.util.Date()).getTime()));
        project.setEnterprise_id(enterpriseId);
        //根据用户等级判断是否直接创建
        if(Integer.valueOf((String) map.get("level")) < 2) {
            project.setState("正常");
            userMapper.createProject(project);
            notification.setContent(projectName);
            notification.setActivity("让你参与了项目");
            notification.setType("项目");
            notification.setDate(new Timestamp((new java.util.Date()).getTime()));
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setIssuer_id(userId);
            notification.setEnterprise_id(enterpriseId);
            for(int i = 0;i < list.size();i++){
                if((Integer) list.get(i) != userId){
                    notification.setRecipient_id((Integer) list.get(i));
                    userMapper.createNotification(notification);
                    goEasy.publish(String.valueOf(list.get(i)), "您有一条关于项目的新消息，请到消息查看详情");
                }
            }
            return 1;
        }else{
            int postId = userMapper.getManagerPostId(enterpriseId).getId();
            int managerId = userMapper.getManagerId(enterpriseId,postId).getId();
            if(managerId == 0) {
                return 2;
            }
            project.setState("待启动");
            userMapper.createProject(project);
            Examine examine = new Examine();
            SimpleDateFormat simpleDateFormat;
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            String str = simpleDateFormat.format(date);
            Random random = new Random();
            int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
            String rouge = "";
            if(project.getRouge() == 0){
                rouge = "私有：只有加入的成员才能看见此项目";
            }else {
                rouge = "公开：企业所有成员都可以看见此项目";
            }

            examine.setNumber(str + ranNum);
            examine.setContent("创建一个新项目");
            examine.setDate(new Timestamp((new java.util.Date()).getTime()));
            examine.setDetail("项目名称：" + project.getProject_name() +",项目编号" + project.getProject_number()
            + ",可见范围：" + rouge + ",项目描述:" + project.getDescription() + ",项目成员id:" + project.getMember_id());
            examine.setApplicant_id(userId);
            examine.setEnterprise_id(enterpriseId);
            examine.setType(0);
            userMapper.createExamine(examine);
            int examineId = userMapper.getExamineId(str + ranNum).getId();

            ExamineProcess examineProcess = new ExamineProcess();
            examineProcess.setExamine_id(examineId);
            examineProcess.setExamine_p_id(managerId);
            examineProcess.setEnterprise_id(enterpriseId);
            userMapper.createExamineProcess(examineProcess);

            notification.setContent("审批编号：" + examine.getNumber());
            notification.setActivity("向你申请审核");
            notification.setType("审核");
            notification.setEnterprise_id(enterpriseId);
            notification.setDate(new Timestamp((new java.util.Date()).getTime()));
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setRecipient_id(managerId);
            notification.setIssuer_id(userId);
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf(managerId), "您有一条关于审核的新消息，请到消息界面查看详情");
            return 3;
        }
    }

    @Override
    public int createTarget(HashMap<String, Object> map) {
        Mission mission = new Mission();
        Target target = new Target();
        Notification notification = new Notification();
        Activity activity = new Activity();
        GoEasy goEasy = new GoEasy("rest-hangzhou.goeasy.io","BC-f92a140e428c4ce79442bafc26e543d8");
        mission.setTitle((String) map.get("title"));
        mission.setProject_id((int) map.get("projectValue"));
        mission.setType("项目目标");
        mission.setPriority((String) map.get("priority"));
        mission.setDescription((String) map.get("missionContent"));
        int enterpriseId = (Integer.valueOf((String) map.get("enterprise_id")));
        int userId = Integer.valueOf((String) map.get("creatorId"));
        String issuerName = userMapper.getUserMessage(userId).getName();
        String issuerPhoto = userMapper.getUserMessage(userId).getPhoto();
        Date date = new Timestamp((new java.util.Date()).getTime());
        mission.setCreator_id(userId);
        mission.setEnterprise_id(enterpriseId);
        mission.setCreate_date(date);
        target.setEnterprise_id(enterpriseId);
        target.setTarget_status("未开始");
        int ProjectPrincipalId = projectMapper.getProjectMessage((int) map.get("projectValue")).getPrincipal_id();
        //根据用户等级判断是否直接创建
        if(Integer.valueOf((String) map.get("level")) < 2 || ProjectPrincipalId == userId) {
            mission.setStatus(0);
            userMapper.createMission(mission);
            target.setMission_id(mission.getId());
            userMapper.createTarget(target);
            activity.setMission_id(mission.getId());
            activity.setUpdate_p_id(userId);
            activity.setUpdate_content("创建任务");
            activity.setUpdate_after("标题："+ map.get("title") + ",状态：未开始," + "优先级："+ map.get("priority"));
            activity.setUpdate_date(date);
            activity.setEnterprise_id(enterpriseId);
            userMapper.createActivity(activity);
            return 1;
        }else{
            String projectNumber = projectMapper.getProjectMessage((int) map.get("projectValue")).getProject_number();
            int PrincipalId = projectMapper.getProjectMessage((int) map.get("projectValue")).getPrincipal_id();
            if(PrincipalId == 0) {
                return 2;
            }
            mission.setStatus(3);
            userMapper.createMission(mission);
            target.setMission_id(mission.getId());
            userMapper.createTarget(target);
            activity.setMission_id(mission.getId());
            activity.setUpdate_p_id(userId);
            activity.setUpdate_content("创建任务");
            activity.setUpdate_after("标题："+ map.get("title") + ",状态：未开始," + "优先级："+ map.get("priority"));
            activity.setUpdate_date(date);
            activity.setEnterprise_id(enterpriseId);
            userMapper.createActivity(activity);

            Examine examine = new Examine();
            SimpleDateFormat simpleDateFormat;
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date1 = new Date();
            String str = simpleDateFormat.format(date1);
            Random random = new Random();
            int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数

            examine.setNumber(str + ranNum);
            examine.setContent("创建一个新项目目标");
            examine.setDate(date);
            examine.setDetail("目标名称：" + mission.getTitle() +",任务编号" + mission.getId()
                    + ",任务描述:" + mission.getDescription() + ",优先级:" + mission.getPriority()
                    + ",所属项目编号:" + projectNumber);
            examine.setApplicant_id(userId);
            examine.setEnterprise_id(enterpriseId);
            examine.setType(1);
            userMapper.createExamine(examine);
            int examineId = userMapper.getExamineId(str + ranNum).getId();

            ExamineProcess examineProcess = new ExamineProcess();
            examineProcess.setExamine_id(examineId);
            examineProcess.setExamine_p_id(PrincipalId);
            examineProcess.setEnterprise_id(enterpriseId);
            userMapper.createExamineProcess(examineProcess);

            notification.setContent("审批编号：" + examine.getNumber());
            notification.setActivity("向你申请审核");
            notification.setType("审核");
            notification.setEnterprise_id(enterpriseId);
            notification.setDate(date);
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setRecipient_id(PrincipalId);
            notification.setIssuer_id(userId);
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf(PrincipalId), "您有一条关于审核的新消息，请到消息界面查看详情");
            return 3;
        }
    }

    @Override
    public int createCost(HashMap<String, Object> map) {
        Mission mission = new Mission();
        Cost cost = new Cost();
        Notification notification = new Notification();
        Activity activity = new Activity();
        GoEasy goEasy = new GoEasy("rest-hangzhou.goeasy.io","BC-f92a140e428c4ce79442bafc26e543d8");
        mission.setTitle((String) map.get("title"));
        mission.setProject_id((int) map.get("projectValue"));
        mission.setType("项目费用");
        mission.setDescription((String) map.get("missionContent"));
        int enterpriseId = (Integer.valueOf((String) map.get("enterprise_id")));
        int userId = Integer.valueOf((String) map.get("creatorId"));
        String issuerName = userMapper.getUserMessage(userId).getName();
        String issuerPhoto = userMapper.getUserMessage(userId).getPhoto();
        Date date = new Timestamp((new java.util.Date()).getTime());
        mission.setCreator_id(userId);
        mission.setEnterprise_id(enterpriseId);
        mission.setCreate_date(date);
        mission.setPrincipal_id((int) map.get("missionPrincipalValue"));
        String MissionMembers = "";
        //加项目参与人
        String projectMembers = projectMapper.getProjectMessage((int) map.get("projectValue")).getMember_id();
        List<Integer> oldList = Arrays.asList(projectMembers.substring(1).split( ",")).stream().map(Integer::parseInt).collect(Collectors.toList());
        ArrayList list = (ArrayList) map.get("financialStaffs");
        Set<Integer> set1 = new HashSet(oldList);
        Set<Integer> set2 = new HashSet<Integer>(list);
        Sets.SetView<Integer> add = Sets.difference(set2,set1);

        for(int i = 0;i < list.size();i++){
            if(i == 0){
                MissionMembers = "," + MissionMembers + list.get(i) + ",";
            }else{
                MissionMembers = MissionMembers + list.get(i) + ",";
            }
        }
        mission.setParticipant_id(MissionMembers);
        cost.setEnterprise_id(enterpriseId);
        cost.setFinance((String) map.get("finance"));
        cost.setBudget(Double.valueOf(map.get("budget").toString()));
        cost.setExecute(Double.valueOf(map.get("performAccount").toString()));
        cost.setCost_state("未发生");
        int ProjectPrincipalId = projectMapper.getProjectMessage((int) map.get("projectValue")).getPrincipal_id();
        //根据用户等级判断是否直接创建
        if(Integer.valueOf((String) map.get("level")) < 2 || ProjectPrincipalId == userId) {
            mission.setStatus(0);
            userMapper.createMission(mission);
            cost.setMission_id(mission.getId());
            userMapper.createCost(cost);

            if(add.size() != 0){
                for(int i = 0;i < add.size(); i++){
                    projectMembers = projectMembers + Arrays.asList(add.toArray()).get(i) + ",";
                }
                HashMap<String,Object> NewMap = new HashMap<>();
                NewMap.put("member_id",projectMembers);
                NewMap.put("id",map.get("projectValue"));
                projectMapper.updateProjectMembers(NewMap);
            }


            activity.setMission_id(mission.getId());
            activity.setUpdate_p_id(userId);
            activity.setUpdate_content("创建任务");
            activity.setUpdate_after("标题："+ map.get("title") + ",状态：未开始");
            activity.setUpdate_date(date);
            activity.setEnterprise_id(enterpriseId);
            userMapper.createActivity(activity);

            notification.setContent(mission.getTitle());
            notification.setActivity("让你参与了任务");
            notification.setType("任务");
            notification.setDate(date);
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setIssuer_id(userId);
            notification.setEnterprise_id(enterpriseId);
            for(int i = 0;i < list.size();i++){
                if((Integer) list.get(i) != userId){
                    notification.setRecipient_id((Integer) list.get(i));
                    userMapper.createNotification(notification);
                    goEasy.publish(String.valueOf(list.get(i)), "您有一条关于任务的新消息，请到消息查看详情");
                }
            }
            notification.setActivity("让你担任该任务负责人");
            notification.setRecipient_id((int) map.get("missionPrincipalValue"));
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf((int) map.get("missionPrincipalValue")), "您有一条关于任务的新消息，请到消息查看详情");
            return 1;
        }else{
            String projectNumber = projectMapper.getProjectMessage((int) map.get("projectValue")).getProject_number();
            int PrincipalId = projectMapper.getProjectMessage((int) map.get("projectValue")).getPrincipal_id();
            if(PrincipalId == 0) {
                return 2;
            }

            mission.setStatus(3);
            userMapper.createMission(mission);
            cost.setMission_id(mission.getId());
            userMapper.createCost(cost);

            activity.setMission_id(mission.getId());
            activity.setUpdate_p_id(userId);
            activity.setUpdate_content("创建任务");
            activity.setUpdate_after("标题："+ map.get("title") + ",状态：未开始");
            activity.setUpdate_date(date);
            activity.setEnterprise_id(enterpriseId);
            userMapper.createActivity(activity);

            Examine examine = new Examine();
            SimpleDateFormat simpleDateFormat;
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date1 = new Date();
            String str = simpleDateFormat.format(date1);
            Random random = new Random();
            int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数

            examine.setNumber(str + ranNum);
            examine.setContent("创建一个新项目费用");
            examine.setDate(date);
            examine.setDetail("费用名称：" + mission.getTitle() +",任务编号" + mission.getId()
                    + ",描述:" + mission.getDescription() + ",财务科目:" + cost.getFinance() + "预算金额：" + cost.getBudget()
                    + "元,执行金额：" + cost.getExecute() + "元,所属项目编号:" + projectNumber);
            examine.setApplicant_id(userId);
            examine.setEnterprise_id(enterpriseId);
            examine.setType(1);
            userMapper.createExamine(examine);
            int examineId = userMapper.getExamineId(str + ranNum).getId();

            ExamineProcess examineProcess = new ExamineProcess();
            examineProcess.setExamine_id(examineId);
            examineProcess.setExamine_p_id(PrincipalId);
            examineProcess.setEnterprise_id(enterpriseId);
            userMapper.createExamineProcess(examineProcess);

            notification.setContent("审批编号：" + examine.getNumber());
            notification.setActivity("向你申请审核");
            notification.setType("审核");
            notification.setEnterprise_id(enterpriseId);
            notification.setDate(date);
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setRecipient_id(PrincipalId);
            notification.setIssuer_id(userId);
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf(PrincipalId), "您有一条关于审核的新消息，请到消息界面查看详情");
            return 3;
        }
    }

    @Override
    public int createProjectMission(HashMap<String, Object> map) throws ParseException {
        Mission mission = new Mission();
        MissionProject missionProject = new  MissionProject();
        Notification notification = new Notification();
        Activity activity = new Activity();
        GoEasy goEasy = new GoEasy("rest-hangzhou.goeasy.io","BC-f92a140e428c4ce79442bafc26e543d8");
        mission.setTitle((String) map.get("title"));
        mission.setProject_id((int) map.get("projectValue"));
        mission.setType("项目任务");
        mission.setDescription((String) map.get("missionContent"));
        int enterpriseId = (Integer.valueOf((String) map.get("enterprise_id")));
        int userId = Integer.valueOf((String) map.get("creatorId"));
        String issuerName = userMapper.getUserMessage(userId).getName();
        String issuerPhoto = userMapper.getUserMessage(userId).getPhoto();
        Date date = new Timestamp((new java.util.Date()).getTime());
        mission.setCreator_id(userId);
        mission.setEnterprise_id(enterpriseId);
        mission.setCreate_date(date);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mission.setStart_date(sdf.parse((String) map.get("missionStart")));
        mission.setOver_date(sdf.parse((String) map.get("missionOver")));
        mission.setPriority((String) map.get("priority"));
        mission.setPrincipal_id((int) map.get("missionPrincipalValue"));
        String MissionMembers = "";
        //加项目参与人
        String projectMembers = projectMapper.getProjectMessage((int) map.get("projectValue")).getMember_id();
        List<Integer> oldList = Arrays.asList(projectMembers.substring(1).split( ",")).stream().map(Integer::parseInt).collect(Collectors.toList());
        ArrayList list = (ArrayList) map.get("missionMember");
        Set<Integer> set1 = new HashSet(oldList);
        Set<Integer> set2 = new HashSet<Integer>(list);
        Sets.SetView<Integer> add = Sets.difference(set2,set1);

        for(int i = 0;i < list.size();i++){
            if(i == 0){
                MissionMembers = "," + MissionMembers + list.get(i) + ",";
            }else{
                MissionMembers = MissionMembers + list.get(i) + ",";
            }
        }

        mission.setParticipant_id(MissionMembers);
        missionProject.setEnterprise_id(enterpriseId);
        missionProject.setPhase((String) map.get("projectProcess"));
        missionProject.setPM_state("未开始");
        int ProjectPrincipalId = projectMapper.getProjectMessage((int) map.get("projectValue")).getPrincipal_id();
        //根据用户等级判断是否直接创建
        if(Integer.valueOf((String) map.get("level")) < 2 || ProjectPrincipalId == userId) {
            mission.setStatus(0);
            userMapper.createMission(mission);
            missionProject.setMission_id(mission.getId());
            userMapper.createProjectMission(missionProject);

            if(add.size() != 0){
                for(int i = 0;i < add.size(); i++){
                    projectMembers = projectMembers + Arrays.asList(add.toArray()).get(i) + ",";
                }
                HashMap<String,Object> NewMap = new HashMap<>();
                NewMap.put("member_id",projectMembers);
                NewMap.put("id",map.get("projectValue"));
                projectMapper.updateProjectMembers(NewMap);
            }


            activity.setMission_id(mission.getId());
            activity.setUpdate_p_id(userId);
            activity.setUpdate_content("创建任务");
            activity.setUpdate_after("标题："+ map.get("title") + ",状态：未开始" + ",优先级：" + map.get("priority") + ",项目阶段:" + map.get("projectProcess"));
            activity.setUpdate_date(date);
            activity.setEnterprise_id(enterpriseId);
            userMapper.createActivity(activity);

            notification.setContent(mission.getTitle());
            notification.setActivity("让你参与了任务");
            notification.setType("任务");
            notification.setDate(date);
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setIssuer_id(userId);
            notification.setEnterprise_id(enterpriseId);
            for(int i = 0;i < list.size();i++){
                if((Integer) list.get(i) != userId){
                    notification.setRecipient_id((Integer) list.get(i));
                    userMapper.createNotification(notification);
                    goEasy.publish(String.valueOf(list.get(i)), "您有一条关于任务的新消息，请到消息查看详情");
                }
            }
            notification.setActivity("让你担任该任务负责人");
            notification.setRecipient_id((int) map.get("missionPrincipalValue"));
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf((int) map.get("missionPrincipalValue")), "您有一条关于任务的新消息，请到消息查看详情");
            return 1;
        }else{
            String projectNumber = projectMapper.getProjectMessage((int) map.get("projectValue")).getProject_number();
            int PrincipalId = projectMapper.getProjectMessage((int) map.get("projectValue")).getPrincipal_id();
            if(PrincipalId == 0) {
                return 2;
            }

            mission.setStatus(3);
            userMapper.createMission(mission);
            missionProject.setMission_id(mission.getId());
            userMapper.createProjectMission(missionProject);

            activity.setMission_id(mission.getId());
            activity.setUpdate_p_id(userId);
            activity.setUpdate_content("创建任务");
            activity.setUpdate_after("标题："+ map.get("title") + ",状态：未开始" + ",优先级：" + map.get("priority") + ",项目阶段:" + map.get("projectProcess"));
            activity.setUpdate_date(date);
            activity.setEnterprise_id(enterpriseId);
            userMapper.createActivity(activity);

            Examine examine = new Examine();
            SimpleDateFormat simpleDateFormat;
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date1 = new Date();
            String str = simpleDateFormat.format(date1);
            Random random = new Random();
            int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数

            examine.setNumber(str + ranNum);
            examine.setContent("创建一个新项目任务");
            examine.setDate(date);
            examine.setDetail("任务名称：" + mission.getTitle() +",任务编号" + mission.getId()
                    + ",描述:" + mission.getDescription() + ",开始时间:" + mission.getStart_date()+ ",结束时间：" + mission.getOver_date()
                    + ",项目阶段：" + missionProject.getPhase() + ",优先级:" + mission.getPriority() + ",所属项目编号:" + projectNumber);
            examine.setApplicant_id(userId);
            examine.setEnterprise_id(enterpriseId);
            examine.setType(1);
            userMapper.createExamine(examine);
            int examineId = userMapper.getExamineId(str + ranNum).getId();

            ExamineProcess examineProcess = new ExamineProcess();
            examineProcess.setExamine_id(examineId);
            examineProcess.setExamine_p_id(PrincipalId);
            examineProcess.setEnterprise_id(enterpriseId);
            userMapper.createExamineProcess(examineProcess);

            notification.setContent("审批编号：" + examine.getNumber());
            notification.setActivity("向你申请审核");
            notification.setType("审核");
            notification.setEnterprise_id(enterpriseId);
            notification.setDate(date);
            notification.setIssuer_name(issuerName);
            notification.setIssuer_photo(issuerPhoto);
            notification.setRecipient_id(PrincipalId);
            notification.setIssuer_id(userId);
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf(PrincipalId), "您有一条关于审核的新消息，请到消息界面查看详情");
            return 3;
        }
    }


    @Override
    public int updateNotificationStatue(int id) {
        return userMapper.updateNotificationStatue(id);
    }

    @Override
    public int deleteMessage(int id){
        return userMapper.deleteMessage(id);
    }

    @Override
    public int createExamine(HashMap<String, Object> map) {
        GoEasy goEasy = new GoEasy("rest-hangzhou.goeasy.io","BC-f92a140e428c4ce79442bafc26e543d8");
        Examine examine = new Examine();
        SimpleDateFormat simpleDateFormat;
        simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Timestamp((new java.util.Date()).getTime());
        User user = userMapper.getUserMessage(Integer.valueOf((String)map.get("userId")));

        Date date1 = new Date();
        String str = simpleDateFormat.format(date1);
        Random random = new Random();
        int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数

        examine.setNumber(str + ranNum);
        examine.setContent((String) map.get("content"));
        examine.setDate(date);
        examine.setDetail((String) map.get("examineContent"));
        examine.setApplicant_id(Integer.valueOf((String)map.get("userId")));
        examine.setEnterprise_id(Integer.valueOf((String)map.get("enterpriseId")));
        examine.setType(2);
        int examineId = userMapper.createExamine(examine);

        ExamineProcess examineProcess = new ExamineProcess();
        ArrayList examinePeople = (ArrayList) map.get("examinePeople");
        for(int i = 0;i < examinePeople.size() ; i++){
            examineProcess.setExamine_id(examineId);
            examineProcess.setExamine_p_id((int)examinePeople.get(i));
            if(examinePeople.size() > 1 && i != examinePeople.size() - 1){
                examineProcess.setNext_p_id((int)examinePeople.get(i+1));
            }
            examineProcess.setEnterprise_id(Integer.valueOf((String)map.get("enterpriseId")));
            userMapper.createExamineProcess(examineProcess);

            Notification notification = new Notification();

            notification.setContent("审批编号：" + examine.getNumber());
            notification.setActivity("向你申请审核");
            notification.setType("审核");
            notification.setEnterprise_id(Integer.valueOf((String)map.get("enterpriseId")));
            notification.setDate(date);
            notification.setIssuer_name(user.getUsername());
            notification.setIssuer_photo(user.getPhoto());
            notification.setRecipient_id((int)examinePeople.get(i));
            notification.setIssuer_id(user.getId());
            userMapper.createNotification(notification);
            goEasy.publish(String.valueOf((int)examinePeople.get(i)), "您有一条关于审核的新消息，请到消息界面查看详情");
        }
        return examineId;
    }

    @Override
    public MainPageResult getMainPageResult(int id) {
        System.out.println(id);
        double mainpageHour = 0.0;
        if(userMapper.getMainpageHour(id) != null){
            mainpageHour = userMapper.getMainpageHour(id);
        }


        int mainpageMissionNum = userMapper.getMainpageMissionNum(id);
        int mainpageProjectNum = userMapper.getMainpageProjectNum(id);
        double mainpageMissionFinish = userMapper.getMainpageMissionFinish(id);
        double mainpageMissionDelay = userMapper.getMainpageMissionDelay(id);
        List<ProjectPage> mainpageProjectTop = userMapper.getMainpageProjectTop(id);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (ProjectPage projectPage : mainpageProjectTop) {
            projectPage.setFinish(userMapper.getProjectFinish(projectPage.getId()));
        }
        List<ProjectPage> list = mainpageProjectTop.stream().map(res -> {
        if(res.getPrincipal_id() == 0 ){
            res.setPrincipal_name("无");
        }else{
            res.setPrincipal_name(userMapper.getUserMessage(res.getPrincipal_id()).getName());
        }
        if(res.getFinish() == null){
            res.setFinish(0.0);
        }
        res.setStrCreateDate(sdf.format(res.getCreate_date()));
        if(res.getOver_date() != null){
            res.setStrOverDate(sdf.format(res.getOver_date()));
        }
        if(res.getDelete_date() != null){
            res.setStrDeleteDate(sdf.format(res.getDelete_date()));
        }
        if(res.getStart_date() != null){
            res.setStrStartDate(sdf.format(res.getStart_date()));
        }
        return res;
        }).collect(Collectors.toList());
        return new MainPageResult(true,"主页数据导出成功",mainpageHour,mainpageMissionNum,mainpageProjectNum,mainpageMissionFinish,mainpageMissionDelay,list);
    }

    @Override
    public ReportResult getReportPageResult(int id) {
        ReportResult reportResultHead = userMapper.getReportHead(id);
        List<ReportProject> projectList = userMapper.getProjectList(id);
        for (ReportProject project : projectList) {
            ReportProject projectNumList = userMapper.getProjectNumList(project.getId());
            project.setMissionnum(projectNumList.getMissionnum());
            project.setNotstartmissionnum(projectNumList.getNotstartmissionnum());
            project.setStartmissionnum(projectNumList.getStartmissionnum());
            project.setFinishmissionnum(projectNumList.getFinishmissionnum());
            if(projectNumList.getCompleteness() == null){
                project.setCompleteness(0.0);
            }else{
                project.setCompleteness(projectNumList.getCompleteness());
            }

        }
        reportResultHead.setProjectList(projectList);
        return reportResultHead;
    }

    @Override
    public List<HashMap<String,Object>> getMyDoingMission(int id) {
        List<Mission> missions = missionMapper.getMyDoingMission(id);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<HashMap<String,Object>> list = missions.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            newMap.put("state",res.getStatus());
            if(res.getType().equals("项目目标")){
                newMap.put("status",missionMapper.getTargetMessage(res.getId()).getTarget_status());
            }else if(res.getType().equals("项目费用")){
                newMap.put("status",missionMapper.getCostMessage(res.getId()).getCost_state());
            }else{
                newMap.put("status",missionMapper.getMissionProjectMessage(res.getId()).getPM_state());
            }
            newMap.put("type",res.getType());
            newMap.put("overDate",sdf.format(res.getOver_date()));
            newMap.put("title",res.getTitle());
            return newMap;
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<HashMap<String,Object>> getMyPostponeMission(int id) {
        List<Mission> missions = missionMapper.getMyPostponeMission(id);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<HashMap<String,Object>> list = missions.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("id",res.getId());
            newMap.put("state",res.getStatus());
            if(res.getType().equals("项目目标")){
                newMap.put("status",missionMapper.getTargetMessage(res.getId()).getTarget_status());
            }else if(res.getType().equals("项目费用")){
                newMap.put("status",missionMapper.getCostMessage(res.getId()).getCost_state());
            }else{
                newMap.put("status",missionMapper.getMissionProjectMessage(res.getId()).getPM_state());
            }
            newMap.put("type",res.getType());
            newMap.put("overDate",sdf.format(res.getOver_date()));
            newMap.put("title",res.getTitle());
            return newMap;
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<HashMap<String,Object>> getDepartment(int id){
        List<Department> departments = userMapper.getDepartment(id);
        List<HashMap<String,Object>> list = departments.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("value",res.getId());
            newMap.put("label",res.getDepart_name());
            return newMap;
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<HashMap<String,Object>> getPost(int id){
        List<Post> posts = userMapper.getPost(id);
        List<HashMap<String,Object>> list = posts.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("value",res.getId());
            newMap.put("label",res.getPost_name());
            return newMap;
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<HashMap<String,Object>> getMoveDepartment(int id){
        List<Department> departments = userMapper.getMoveDepartment(id);
        List<HashMap<String,Object>> list = departments.stream().map(res -> {
            HashMap<String,Object> newMap = new HashMap<>();
            newMap.put("value",res.getId());
            newMap.put("label",res.getDepart_name());
            return newMap;
        }).collect(Collectors.toList());
        return list;
    }
}
